home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_gen / gcoope10.zip / OBJLIST.C < prev    next >
Text File  |  1994-07-21  |  4KB  |  139 lines

  1. /*
  2.  
  3.     object list manager for GCOOPE Version 1.0
  4.  
  5.             by Brian Lee Price
  6.  
  7.     Released as Public Domain   July, 1994.
  8.  
  9.     This group of routines track all objects (including classes).
  10.     This is where any object that has instance variables goes to
  11.     access the correct memory area.
  12.         Be sure and examine gcstruct.h and listmgr.c prior to any
  13.     serious reading of this file.
  14.  
  15. */
  16.  
  17. #define __OBJECTS__
  18.  
  19. #include "gcstruct.h"
  20.  
  21.  
  22. /*
  23. FOR KERNEL USE ONLY!
  24.  
  25. usage:
  26.    objectEntryStructurePointer=getObject(object_tag_value);
  27.  
  28.    Okay what is a tag_value?  While the type 'object' is a 32bit value,
  29.    in many cases only 14 bits are actually required.  Given an 'object',
  30.    use the macro OBJFLAG to turn the object var into a pointer to a
  31.    objflag struct and use the tag member to get or set the tag value.
  32.     Most accesses are performed via the use of the tag
  33.    values, but for a number of reasons (no instance memory for
  34.    char, int, and full representation, instance variable access
  35.    speed up techniques, etc.) 'object' must be a 32 bit value.
  36.        This routine returns the pointer to a descriptor entry in the
  37.    object list assigned to the tag value objTag, where objTag is an
  38.    index to an unordered list.  On error a NULL pointer is returned so,
  39.    VALIDATE THOSE RETURN POINTER VALUES!!!
  40.     The objectEntry structure contains the object's process ID
  41.    number, it's last access value (for garbage collection), and
  42.    finally a pointer to the object definition.
  43.  
  44. */
  45.  
  46. objectEntry * getObject(tag objTag)
  47. {
  48. objectEntry * retVal=NULL;
  49.  
  50. if(objList.listPtr!=NULL && objTag < objList.maxElems && objTag>0)
  51.     {
  52.     retVal=objList.listPtr;
  53.     retVal+=objTag;
  54.     }
  55. return retVal;
  56. }
  57.  
  58.  
  59.  
  60. /*
  61. FOR KERNEL USE ONLY!
  62.  
  63. usage:
  64.    objectDefinitionPointer=getObjDef(object_tag_value);
  65.  
  66.     See above comments for getObject, the only difference here is
  67.    that the pointer to the object definition is obtained from the
  68.    objectEntry structure and that is the pointer returned to the caller.
  69. */
  70.  
  71. void * getObjDef(tag objTag)
  72. {
  73. objectEntry * objEntry;
  74.  
  75. if(NULL==(objEntry=getObject(objTag))) return NULL;
  76. objEntry->lastAcc=INIT_AGE;
  77. return objEntry->objDef;
  78. }
  79.  
  80.  
  81.  
  82. /*
  83. FOR KERNEL USE ONLY!
  84.  
  85. usage:
  86.     newObjectTagValue=addObject(objectDefinitionPointer, processID);
  87.     The value processID is used to enable the garbage collection
  88.     mechanism to be multi-thread aware, it is also used by makePerm
  89.     and in newClass to prevent the garbage collector from killing off
  90.     a non-temporary object.
  91.     The object definition pointer must be a valid pointer to a
  92.     structure of type objDefinition.  The function returns the tag
  93.     value of the new object.
  94.     Note that on an error this function returns the value BAD_OBJ.
  95. */
  96.  
  97. int addObject(void * objDef, byte procID)
  98. {
  99. int         x;
  100. objectEntry *     newObj;
  101.  
  102. if(objDef==NULL || (x=addItem(&objList, sizeof(objectEntry)))<0)
  103.     return BAD_OBJ;
  104. newObj=objList.listPtr;
  105. newObj+=x;
  106. newObj->objDef=objDef;
  107. newObj->procID=procID;
  108. newObj->lastAcc=INIT_AGE;
  109. return x;
  110. }
  111.  
  112.  
  113. /*
  114. FOR KERNEL USE ONLY!
  115.  
  116. usage:
  117.     functionStatus=rmvObject(object_tag_value);
  118.     This function removes an object Entry from the objList after
  119.     freeing the object definition memory area (if not already freed).
  120.     It returns the FUNCOKAY/FUNCFAIL value.
  121. */
  122.  
  123.  
  124. int rmvObject(tag objTag)
  125. {
  126. short         retVal=FUNCFAIL;
  127. objectEntry *     oldObj;
  128.  
  129. if(NULL==(oldObj=getObject(objTag))) goto end;
  130. if(oldObj->objDef!=NULL) s_free(oldObj->objDef);
  131. if(rmvItem(&objList, objTag)<0) goto end;
  132. retVal=FUNCOKAY;
  133. end:
  134. return retVal;
  135. }
  136.  
  137.  
  138.  
  139.